package top.pmwly.serivce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import top.pmwly.common.domain.UserSecurity;
import top.pmwly.service.ISysUserService;

/**
 * @author Herther
 * @version 1.0.0
 * @ClassName UserDetailsServiceImpl.java
 * @Description 重写UserDetails
 * @createTime 2021年09月21日 20:40:00
 */
@Component
public class UserDetailsServiceImpl implements UserDetailsService {


    @Autowired
    private ISysUserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //查询根据用户名查询 用户信息
        UserSecurity sysUser = userService.getInfo(username);
        if (null == sysUser){
            return null;
        }
        return createLoginUser(sysUser);
    }

    private UserDetails createLoginUser(UserSecurity user) {
       return user;
    }

}
